import {Injectable} from '@angular/core';
import {url} from './url'

declare var $: any;
@Injectable()
export class FileInputPluginService {
  public imageUploadUrl:string = url.url+'/app2/upload';
  constructor() {
  }

  showFileInputPlugin(ele, maxFileCount, initalPreviewConfig,initalPreviewConfig2) {
    $(ele).fileinput({
      language: 'zh',
      theme: "fa",
      uploadUrl: this.imageUploadUrl,
      // uploadUrl: "http://rapapi.org/mockjsdata/20823/upload/images",
      allowedFileExtensions: ['jpg', 'png', 'gif'],
      showClose: false,
      // layoutTemplates:false,
      maxFileCount: maxFileCount,
      uploadLabel: '上传',
      cancelLabel: '取消',
      msgFileRequired: '您必须选择一个文件上传',
      msgUploadEnd: '完成',
      dropZoneTitle: "可通过拖拽图片放到这里",
      browseLabel: '浏览器',
      dropZoneClickTitle: "或者点击此区域添加图片",
      uploadsync: true,
      enctype: 'multipart/form-data',
      // uploadExtraData: {postiton: uploadExtraData},
      msgUploadThreshold: '上传中...',
      msgUploadEmpty: '没有图片上传.',
      msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",
      msgLoading: '正在上传{index} of {files} &hellip;',
      msgProgress: '上传进度: {index} 的 {files} - {name} - {percent}%.',
      msgFileNotFound: '文件 "{name}" 没有找到!',
      msgInvalidFileType: '无效的类型 "{name}". 只有 "{types}" 类型文件是支持的.',
      msgUploadBegin: '开始上传...',
      msgAjaxError: '{operation} 过程中出错了. 请稍后尝试,或者联系我们!',
      msgAjaxProgressError: '{operation} 失败!',
      ajaxOperations: {
        deleteThumb: '删除图片',
        uploadThumb: '上传图片',
        uploadBatch: 'batch file upload',
        uploadExtra: 'form data upload'
      },
      // hideThumbnailContent: true // hide image, pdf, text or other content in the thumbnail preview
      overwriteInitial: false,
      initialPreviewAsData: true,
      // initialPreview: initalPreviewConfig,
      initialPreview:
        initalPreviewConfig
        // `<img src='/images/desert.jpg' class='file-preview-image' alt='Desert' title='Desert'>`,
      ,
      initialPreviewConfig: initalPreviewConfig2
    });
  }

}
